﻿using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using LASGui.MainService;

namespace LASGui.Classes
{
    public class AuthenticatedUser
    {
        static AuthenticatedUser _instance;
        static readonly object SingletonLock = new object();

        protected AuthenticatedUser() { }

        public LasUser OnlineUser { get; set; }
        public List<Currency> CompanyCurrency { get; set; }

        /// <summary>
        /// Método de encriptación md5 para un string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string EncryptToMd5(string value)
        {
            var data = MD5Core.GetHash(value);
            var sBuilder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }
        
        /// <summary>
        /// Singleton
        /// </summary>
        public static AuthenticatedUser Instance
        {
            get
            {
                lock (SingletonLock)
                {
                    return _instance ?? (_instance = new AuthenticatedUser());
                }
            }
        }
    }
}